/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package pope.jloading.mycell;

import java.awt.Color;
import java.awt.Component;
import javax.swing.JLabel;
import javax.swing.JTable;
import javax.swing.table.TableCellRenderer;

/**
 *
 * @author zouxw
 */
public class ColumnCellRenderer extends JLabel implements TableCellRenderer{
    Color color = new Color(246, 246, 246);
    
    public ColumnCellRenderer() {
        setOpaque(true);
    }
    
    public Component getTableCellRendererComponent(JTable table, 
            Object value, 
            boolean isSelected, 
            boolean hasFocus, 
            int row, int column) {
        if (isSelected) {
            setForeground(table.getSelectionForeground());
            setBackground(table.getSelectionBackground());
        } else {
            if ((row % 2) == 0) {
                setBackground(Color.WHITE);
            } else {
                setBackground(color);
            }
            setForeground(table.getForeground());
        }
        setText(String.valueOf(value));
        return this;
    }
}
